#!/usr/bin/perl

use strict;

use lib qw( lib t/lib );
use SQLiteTest;
use DataValidatorSchemaLoader;
use Data::Dumper;
use Test::More tests => 3;

my $schema = SQLiteTest::get_test_schema( "DataValidatorSchemaLoader" );
my $id = 10;

ok( test_create(), "Test normal creation with Loader" );
ok( test_create_validated_ok(), "Test create validated with SQLite specific datatype validation" );
ok( test_update_validated_ok(), "Test update validated with SQLite specific datatype validation" );


sub test_create {
    $schema->rescan;
    eval {
        my $test = $schema->resultset( 'Foo' )->create( {
            name => 'normal',
            id   => $id++,
        } );
    };
    return $@ ? 0 : 1;
}

sub test_create_validated_ok {
    eval {
        my $test = $schema->resultset( 'Foo' )->create_validated( {
            name => 'foo is validated',
            id   => 'c'
        } );
    };
    return $@ ? 1 : 0;
}

sub test_update_validated_ok {
    my $test = $schema->resultset( 'Foo' )->first;
    eval {
        $test->update_validated( { id => 'a' } );
    };
    return $@ ? 1 : 0;
}


1;
